import serial
import hexdump
import argparse


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--port', type=str, default='COM126')
    parser.add_argument('-b', '--baudrate', type=int, default=115200)
    parser.add_argument('-t', '--timeout', type=int, default=0)
    parser.add_argument('-l', '--datalen', type=int, default=1)
    return parser.parse_args()

def main(args):
    
    data = bytes([i for i in range(args.datalen)])
    #hexdump.hexdump(data)

    s = serial.Serial(port=args.port, baudrate=args.baudrate, timeout=args.timeout)
    s.write(data)
    s.close()


if __name__ == '__main__':
    args = parse_args()
    try:
        main(args)
    except Exception as e:
        print(e)